//
//  MoreInformationViewController.m
//  喜马拉雅FM
//
//  Created by dllo on 16/3/3.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#import "MoreInformationViewController.h"

#import "NetworkHandlerBlock.h"
#import "ModelForListen.h"
#import "ItemVC2TableViewCell.h"
#import "SecendViewController.h"


@interface MoreInformationViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrForMoreInformation;

@end

@implementation MoreInformationViewController


- (void)dealloc {

    [_tableView release];
    [_arrForMoreInformation release];
    [super dealloc];
}

#pragma mark VC的生命周期.


- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    // 系统返回键颜色.
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];

//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]}];
//    self.navigationController.navigationBar.translucent = NO;
    [self handleDataForXiaoBianRecomment];
    [self createTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)handleDataForXiaoBianRecomment {
    
    self.arrForMoreInformation = [NSMutableArray array];
    [NetworkHandlerBlock netWorkingWithURL:@"http://mobile.ximalaya.com/mobile/discovery/v1/recommend/editor?device=android&pageId=1&pageSize=20&title=%E6%9B%B4%E5%A4%9A" completeHandle:^(NSURLResponse *response, NSData *data, id result) {
        
        NSArray *tempArr = [result objectForKey:@"list"];
        for (NSDictionary *dic in tempArr) {
            ModelForListen *modelForRemment = [[ModelForListen alloc]init];
            [modelForRemment setValuesForKeysWithDictionary:dic];
            [self.arrForMoreInformation addObject:modelForRemment];
        }
        [self.tableView reloadData];
        NSLog(@"%@,   %lu",self.arrForMoreInformation,self.arrForMoreInformation.count);
    }];
}

- (void)createTableView {
    
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.tableView registerClass:[ItemVC2TableViewCell class] forCellReuseIdentifier:@"poolForUITableViewCell"];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.arrForMoreInformation.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ModelForListen *model = [self.arrForMoreInformation objectAtIndex:indexPath.row];
    ItemVC2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"poolForUITableViewCell"];
    [cell passModelForListen:model];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ModelForListen *model = [self.arrForMoreInformation objectAtIndex:indexPath.row];
    SecendViewController *secend = [[SecendViewController alloc]init];
    secend.stringForAlbumID = model.albumId;
    secend.modelForListen = model;
    [self.navigationController pushViewController:secend animated:YES];
 
}

@end
